home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / DVIM72-Mac 1.9.6 / source / configure.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-14  |  11.9 KB  |  461 lines  |  [TEXT/R*ch]

  1. #include <stdarg.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <PrintTraps.h>
  5. #include "TextDisplay.h"
  6. #include "dvihead.h"
  7. #include "gendefs.h"
  8. #include "egblvars.h"
  9. #include "mac-specific.h"
  10. #include "Copy_banded.h"
  11.  
  12. extern int            g_dpi;
  13. extern WindowPtr    g_freemem_window;
  14. extern THPrint        g_print_rec_h;
  15. extern MenuHandle    g_popup_menu;
  16. extern int            g_printer_dpi;    /* device resolution */
  17.  
  18. #define SFGET_ID    4045
  19. #define REVEAL_DIALOG(d) {SelectWindow(d);ShowWindow(d);}
  20. #define MOVE_TO_FRONT    -1L
  21.  
  22. Point            g_popup_corner;
  23.  
  24. /* --------------------- Prototypes --------------------------- */
  25. void    Handle_settings( void );
  26. pascal Boolean Dialog_filter( DialogPtr the_dialog,
  27.                             EventRecord *the_event,
  28.                             int            *item_number );
  29.  
  30. void    Update_freemem( void );
  31.  
  32. pascal
  33. void    Draw_popup(        WindowPtr whatwindow,
  34.                             int whatitem );
  35.  
  36. void    Get_folder_pathname(
  37.                         char *PathNamePtr); /* put it here */
  38. pascal int
  39.         dialog_hook(    int item,
  40.                         DialogPtr dialog_ptr );
  41. ControlHandle
  42.         Get_Ditem_handle( DialogPtr theDialog,
  43.                         int item_no );
  44. Handle    Get_resource_by_id( OSType rsrc_type, int r_id );
  45. void    set_bool_resource( char *rsrc_name,
  46.                         Boolean new_value );
  47. Boolean    get_bool_resource( char *rsrc_name );
  48. char  **get_str_resource( char *rsrc_name );
  49. void    set_str_resource(
  50.                         char *rsrc_name,
  51.                         char *new_value );
  52. int        get_int_resource( char *rsrc_name );
  53. void    set_int_resource(
  54.                         char *rsrc_name,
  55.                         int     new_value );
  56. void    Show_warning(     char *msg );
  57. void    Show_error(     char *msg );
  58. void    Tune_radio(     DialogPtr what_dialog,
  59.                         int on_button, ...);
  60. char    *get_dialog_text(
  61.                         DialogPtr thedialog,
  62.                         int item_num,
  63.                         char *thetext );
  64. void    set_dialog_text(
  65.                         DialogPtr thedialog,
  66.                         int item_num,
  67.                         char *thetext );
  68. void    Print_options(    void );
  69. void    Set_resolution(    void );
  70. void    Memory_options(    void );
  71. void    Font_path(        void );
  72. void    Init_print_rec(    void );
  73. void    Center_window(    WindowPtr my_window );
  74. void Select_folder( char *folder_path );
  75.  
  76.  
  77. /* ------------------------- Handle_settings ---------------------------- */
  78. enum {
  79.     s_OK = 1,
  80.     s_cancel,
  81.     fp_button,
  82.     fp_text,
  83.     fp_popup,
  84.     po_hoffset,
  85.     po_voffset,
  86.     sr_font_360,
  87.     sr_font_144,
  88.     sr_font_300,
  89.     sr_font_other,
  90.     sr_font_text,
  91.     s_page_preview,
  92.     s_draw_offscreen,
  93.     s_max_printer_resolution,
  94.     s_banding
  95. };
  96. void    Handle_settings( void )
  97. {
  98.     int            DLOG_id;
  99.     DialogPtr    the_DLOG;
  100.     char        *s_ptr;
  101.     Boolean        dialog_done;
  102.     short        item_hit;
  103.     ControlHandle    font_text_h, cntrl;
  104.     char        t_str[256];
  105.     short        t_font_dpi, dpi_item;
  106.  
  107.     Boolean        t_pathflag, t_popupflag;
  108.     Rect        popup_rect;
  109.     Handle        popup_handle;
  110.     short            item_type;
  111.     char        nameformat[30];
  112.     char        t_pathstr[256];
  113.     short        menu_choice, mark_char;
  114.     long        menulong;
  115.     Point        where;
  116.     SFReply        reply;
  117.     int            i;
  118.     Boolean        t_preview, t_draw_offscreen, t_max_res, t_banding;
  119.         
  120.     DLOG_id = Get_resource_id( 'DLOG', "settings" );
  121.     the_DLOG = GetNewDialog( DLOG_id, nil, (WindowPtr)MOVE_TO_FRONT );
  122.     Center_window( the_DLOG );
  123.  
  124.     /* Initialize TE blanks */
  125.     s_ptr = *get_str_resource("HOFFSET");
  126.     set_dialog_text( the_DLOG, po_hoffset, s_ptr );
  127.     s_ptr = *get_str_resource("VOFFSET");
  128.     set_dialog_text( the_DLOG, po_voffset, s_ptr );
  129.  
  130.     t_font_dpi = g_dpi;
  131.     switch (t_font_dpi)
  132.     {
  133.         case 360:
  134.             dpi_item = sr_font_360;  break;
  135.         case 144:
  136.             dpi_item = sr_font_144;  break;
  137.         case 300:
  138.             dpi_item = sr_font_300;  break;
  139.         default:
  140.             dpi_item = sr_font_other;  break;
  141.     }
  142.     Tune_radio( the_DLOG, dpi_item,
  143.         sr_font_360, sr_font_144, sr_font_300, sr_font_other, 0 );
  144.     font_text_h = Get_Ditem_handle( the_DLOG, sr_font_text );
  145.     if (dpi_item == sr_font_other)
  146.     {
  147.         NumToString( (long)t_font_dpi, (StringPtr) t_str );
  148.         SetIText( (Handle)font_text_h, (StringPtr) t_str );    
  149.     }
  150.     else
  151.         SetIText( (Handle)font_text_h, "\p" );
  152.  
  153.     s_ptr = *get_str_resource("TEXFONTS");
  154.     set_dialog_text( the_DLOG, fp_text, s_ptr );
  155.     t_pathflag = FALSE;
  156.  
  157.     GetDItem( the_DLOG, fp_popup, &item_type,
  158.         &popup_handle, &popup_rect );
  159.     SetDItem( the_DLOG, fp_popup, item_type,
  160.         (Handle)Draw_popup, &popup_rect );
  161.     g_popup_corner.h = popup_rect.left + 2;
  162.     g_popup_corner.v = popup_rect.bottom;
  163.     SetPort( the_DLOG );
  164.     LocalToGlobal( &g_popup_corner );
  165.  
  166.     /* font name format popup menu */
  167.     (void) strcpy( nameformat, *get_str_resource("NAMEFORMAT") );
  168.     for (i = 1; i <= strlen(nameformat); i++)
  169.     {
  170.         CheckItem( g_popup_menu, i, (nameformat[i-1] == '1') );
  171.     }
  172.     
  173.     t_preview = g_preview;
  174.     SetCtlValue( Get_Ditem_handle(the_DLOG, s_page_preview),
  175.         t_preview );
  176.     t_draw_offscreen = g_draw_offscreen;
  177.     SetCtlValue( Get_Ditem_handle(the_DLOG, s_draw_offscreen),
  178.         t_draw_offscreen );
  179.     t_banding = g_print_by_bands;
  180.     cntrl = Get_Ditem_handle( the_DLOG, s_banding);
  181.     SetCtlValue( cntrl, t_banding );
  182.     if (!t_draw_offscreen)
  183.         HiliteControl( cntrl, 255 ); /* inactive */
  184.     t_max_res = get_bool_resource("MAX RESOLUTION");
  185.     SetCtlValue( Get_Ditem_handle(the_DLOG, s_max_printer_resolution),
  186.          t_max_res );
  187.  
  188.     dialog_done = FALSE;
  189.     REVEAL_DIALOG( the_DLOG );
  190.     TD_activate(FALSE);
  191.     while( dialog_done == FALSE )
  192.     {
  193.         ModalDialog( (ProcPtr)Dialog_filter, &item_hit );
  194.         switch( item_hit )
  195.         {
  196.             case s_OK:
  197.                 dialog_done = TRUE;
  198.                 break;
  199.             case s_cancel:
  200.                 dialog_done = TRUE;
  201.                 break;
  202.             case sr_font_360:
  203.                 t_font_dpi = 360;
  204.                 Tune_radio( the_DLOG, item_hit,
  205.                     sr_font_360, sr_font_144, sr_font_300, sr_font_other, 0 );
  206.                 break;
  207.             case sr_font_144:
  208.                 t_font_dpi = 144;
  209.                 Tune_radio( the_DLOG, item_hit,
  210.                     sr_font_360, sr_font_144, sr_font_300, sr_font_other, 0 );
  211.                 break;
  212.             case sr_font_300:
  213.                 t_font_dpi = 300;
  214.                 Tune_radio( the_DLOG, item_hit,
  215.                     sr_font_360, sr_font_144, sr_font_300, sr_font_other, 0 );
  216.                 break;
  217.             case sr_font_other:
  218.             case sr_font_text:
  219.                 t_font_dpi = -1; /* We'll look at the text later */
  220.                 if (item_hit == sr_font_other)
  221.                     SelIText( the_DLOG, sr_font_text, 0, 32767 );
  222.                 else
  223.                     item_hit = sr_font_other;
  224.                 Tune_radio( the_DLOG, item_hit,
  225.                     sr_font_360, sr_font_144, sr_font_300, sr_font_other, 0 );
  226.                 break;
  227.             case fp_button:
  228.                 Select_folder( t_pathstr );
  229.                 if (t_pathstr[0] != 0)
  230.                 {
  231.                     t_pathflag = TRUE;
  232.                     set_dialog_text( the_DLOG,
  233.                         fp_text, t_pathstr );
  234.                 }
  235.                 break;
  236.             case fp_popup:
  237.                 InvertRect( &popup_rect );
  238.                 menulong = PopUpMenuSelect( g_popup_menu,
  239.                     g_popup_corner.v, g_popup_corner.h, 0 );
  240.                 if ( LoWord(menulong) > 0 )
  241.                 {
  242.                     menu_choice = LoWord(menulong);
  243.                     GetItemMark( g_popup_menu, menu_choice, &mark_char );
  244.                     CheckItem( g_popup_menu, menu_choice,
  245.                         (mark_char == noMark) );
  246.                 }
  247.                 InvertRect( &popup_rect );
  248.                 break;
  249.             case s_page_preview:
  250.                 t_preview = !t_preview;
  251.                 SetCtlValue( Get_Ditem_handle(the_DLOG, s_page_preview),
  252.                     t_preview );
  253.                 break;
  254.             case s_draw_offscreen:
  255.                 t_draw_offscreen = !t_draw_offscreen;
  256.                 SetCtlValue( Get_Ditem_handle(the_DLOG, s_draw_offscreen),
  257.                     t_draw_offscreen );
  258.                 HiliteControl( Get_Ditem_handle(the_DLOG, s_banding),
  259.                     t_draw_offscreen? 0 : 255 );
  260.                 break;
  261.             case s_banding:
  262.                 t_banding = !t_banding;
  263.                 SetCtlValue( Get_Ditem_handle(the_DLOG, s_banding),
  264.                     t_banding );
  265.                 break;
  266.             case s_max_printer_resolution:
  267.                 t_max_res = !t_max_res;
  268.                 SetCtlValue( Get_Ditem_handle(the_DLOG, s_max_printer_resolution),
  269.                      t_max_res );
  270.                 break;
  271.         }
  272.     }
  273.     if (item_hit == s_OK)
  274.     {
  275.         set_str_resource( "HOFFSET",
  276.             get_dialog_text( the_DLOG, po_hoffset, t_str ) );
  277.         set_str_resource( "VOFFSET",
  278.             get_dialog_text( the_DLOG, po_voffset, t_str ) );
  279.         if (t_font_dpi < 0)    /* "other" */
  280.         {
  281.             get_dialog_text( the_DLOG, sr_font_text, t_str );
  282.             (void) sscanf( t_str, "%d", &t_font_dpi );
  283.         }
  284.         if ( t_font_dpi != g_dpi ) /* font dpi changed? */
  285.         {
  286.             set_int_resource( "BITMAP DPI", t_font_dpi );
  287.             g_dpi = t_font_dpi;
  288.         }
  289.         if (t_pathflag)
  290.         {
  291.             set_str_resource( "TEXFONTS", t_pathstr );
  292.             (void)strcpy(subpath,t_pathstr); /* update globals derived */
  293.             (void)strcpy(fontpath,t_pathstr); /* from TEXFONTS */
  294.         }
  295.         
  296.         t_popupflag = FALSE;
  297.         for (i = 1; i <= strlen(nameformat); i++)
  298.         {
  299.             GetItemMark( g_popup_menu, i, &mark_char );
  300.             if ((nameformat[i-1] == '0') && (mark_char != noMark))
  301.             {
  302.                 t_popupflag = TRUE;
  303.                 nameformat[i-1] = '1';
  304.  
  305.             };
  306.             if ((nameformat[i-1] == '1') && (mark_char == noMark))
  307.             {
  308.                 t_popupflag = TRUE;
  309.                 nameformat[i-1] = '0';
  310.             }
  311.         }
  312.         if (t_popupflag)
  313.             set_str_resource( "NAMEFORMAT", nameformat );
  314.         if (t_preview != g_preview)
  315.         {
  316.             g_preview = t_preview;
  317.             set_bool_resource( "PREVIEW", t_preview );
  318.             if (g_preview)
  319.                 ShowWindow( g_page_window );
  320.             else
  321.                 HideWindow( g_page_window );
  322.         }
  323.         if (t_draw_offscreen != g_draw_offscreen)
  324.         {
  325.             g_draw_offscreen = t_draw_offscreen;
  326.             set_bool_resource( "DRAW OFFSCREEN", g_draw_offscreen );
  327.         }
  328.         if ( (t_banding != g_print_by_bands) && g_draw_offscreen )
  329.         {
  330.             g_print_by_bands = t_banding;
  331.             set_bool_resource( "BANDING", g_print_by_bands );
  332.         }
  333.         if (t_max_res != get_bool_resource("MAX RESOLUTION"))
  334.         {
  335.             set_bool_resource( "MAX RESOLUTION", t_max_res );
  336.         }
  337.     }
  338.     DisposDialog( the_DLOG );
  339. }
  340.  
  341.  
  342.  
  343. /* ------------------------- Draw_popup ---------------------------- */
  344. pascal void
  345. Draw_popup( what_window, what_item )
  346.   WindowPtr what_window;
  347.   int what_item;
  348. {
  349.     Rect popup_rect;
  350.     Handle item_h;
  351.     short popup_type;
  352.     
  353.     GetDItem( what_window, what_item, &popup_type, &item_h,
  354.         &popup_rect );
  355.     FrameRect( &popup_rect );
  356.     MoveTo( popup_rect.left + 3, popup_rect.bottom );
  357.     LineTo( popup_rect.right, popup_rect.bottom );
  358.     LineTo( popup_rect.right, popup_rect.top + 3 );
  359. }
  360.  
  361. /* --------------------- Get_Ditem_handle -------------------------- */
  362.  
  363. ControlHandle
  364. Get_Ditem_handle( DialogPtr theDialog, int item_no )
  365. {
  366.     short item_type;
  367.     Rect box;
  368.     Handle item_handle;
  369.     
  370.     GetDItem( theDialog, item_no, &item_type, &item_handle, &box );
  371.     return( (ControlHandle) item_handle );
  372. }
  373.  
  374. /* ----------------------- Tune_radio ----------------------- */
  375. /* 
  376. *    Switch one radio button on and some others off.
  377. *    Input: a handle to the dialog, the item number of the button
  378. *    to turn on, a list of item numbers for buttons to turn off,
  379. *    and a zero to terminate the list.  The "on" button isn't turned
  380. *    on until the end, so if the first item also occurs later on
  381. *    the list, it will end up turned on.  Thus, to reset a radio
  382. *    group, you can list the entire group after the first item.
  383. */
  384. void
  385. Tune_radio( DialogPtr what_dialog, int on_button, ...)
  386. {
  387.     va_list    arg_ptr;
  388.     ControlHandle    button_h;
  389.     int     off_button;
  390.     
  391.     va_start( arg_ptr, on_button );
  392.     while ( (off_button = va_arg(arg_ptr, int)) > 0 )
  393.     {
  394.         button_h = Get_Ditem_handle( what_dialog, off_button );
  395.         SetCtlValue( button_h, (int)FALSE );
  396.     }
  397.     va_end( arg_ptr );
  398.     button_h = Get_Ditem_handle( what_dialog, on_button );
  399.     SetCtlValue( button_h, (int)TRUE );
  400. }
  401.  
  402.  
  403. /* ----------------------- get_dialog_text ------------------------- */
  404. char *get_dialog_text(
  405.         DialogPtr thedialog,
  406.         int item_num,
  407.         char *thetext )
  408. {
  409.     short item_type;
  410.     Handle item_handle;
  411.     Rect item_box;
  412.     
  413.     GetDItem( thedialog, item_num, &item_type, &item_handle, 
  414.         &item_box );
  415.     GetIText( item_handle, (StringPtr)thetext );
  416.     (void)PtoCstr( (StringPtr) thetext );
  417.     return( thetext );
  418. } /* get_dialog_text */
  419.  
  420. /* ----------------------- set_dialog_text ------------------------- */
  421. void
  422. set_dialog_text(
  423.         DialogPtr thedialog,
  424.         int item_num,
  425.         char *thetext )
  426. {
  427.     short item_type;
  428.     Handle item_handle;
  429.     Rect item_box;
  430.     char t_str[255];
  431.     
  432.     strcpy( t_str, thetext );
  433.     GetDItem( thedialog, item_num, &item_type, &item_handle, 
  434.         &item_box );
  435.     SetIText( item_handle, CtoPstr(t_str) );
  436. } /* set_dialog_text */
  437.  
  438. /* --------------------- set_bool_resource ------------------ */
  439. void
  440. set_bool_resource( char *rsrc_name, Boolean new_value )
  441. {
  442.     Handle r_handle;
  443.     char rsrc[100]; /* a copy of the string, since CtoPstr
  444.                     converts in place */
  445.  
  446.     strcpy( rsrc, rsrc_name );
  447.     r_handle = GetNamedResource( 'Bool', CtoPstr(rsrc) );
  448.     
  449.     **(Boolean **)r_handle = new_value;
  450.     
  451.     /* Update the resource file. */
  452.     ChangedResource( r_handle );
  453.     if (ResError() != noErr)
  454.         Show_error("set_bool_resource: ChangedResource error");
  455.     WriteResource( r_handle );
  456.     if (ResError() != noErr)
  457.         Show_error("set_bool_resource: WriteResource error");
  458.     UpdateResFile( g_pref_resfile );
  459.     (void) FlushVol( NIL, g_pref_vRefNum );
  460. }
  461.